package com.cloudsea.yunhaistores.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.util.List;
import java.util.Map;

@Data
@Schema(description = "商家新增商品(SPU)的请求DTO")
public class SpuAddDTO {

    @NotNull(message = "必须指定所属门店")
    private Long storeId;

    @NotBlank(message = "商品名称不能为空")
    @Size(max = 100)
    private String spuName;

    @NotNull(message = "必须指定商品分类")
    @Schema(description = "分类名称")
    private String categoryName;

    private String spuDescription;
    private String spuImageUrl;

    @Valid // 关键：确保嵌套的SKU列表也会被校验
    @NotEmpty(message = "商品必须至少包含一个规格(SKU)")
    private List<SkuAddDTO> skus;

    // ... 未来可以添加属性(attributes)相关的DTO ...

    // DTO内部的嵌套DTO，用于描述SKU
    @Data
    @Schema(description = "新增SPU时附带的SKU信息")
    public static class SkuAddDTO {
        @NotBlank(message = "规格名称不能为空")
        private String skuName;

        @NotNull(message = "价格不能为空")
        private Long price; // 单位：分

        @NotNull(message = "库存不能为空")
        private Integer stock;

        private String skuImageUrl;

        @Schema(description = "规格键值对, e.g., {\"尺寸\": \"大\"}")
        private Map<String, String> specs;
    }
}
